package server.main.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import server.main.config.cache.MybatisPlusRedisCache;
import server.main.pojo.FunctionPage;

import java.util.List;

/**
 * @auther MingHsZzz
 * @Date 2022/9/19  19:18
 * @project main
 * @description
 */


@Mapper
@CacheNamespace(implementation = MybatisPlusRedisCache.class)
public interface FunctionPageMapper extends BaseMapper<FunctionPage> {




    @Select("select * from function_page")
    public List<FunctionPage> getall();


    /**
     * 获取权限信息
     * @param roleid 角色id
     * @return 页面信息
     */
//    @Select("SELECT DISTINCT fp.id,fp.pagename,fp.pagedescribe,fp.title,fp.titleflag,fp.url from server_account ser " +
//            "LEFT JOIN account_role ar on ser.doctor_jobnum = ar.server_account_jobnum " +
//            "LEFT JOIN role r on r.id = ar.role_id " +
//            "LEFT JOIN role_permission rp on rp.role_id = rp.role_id " +
//            "LEFT JOIN permission p on p.id = rp.permission_id " +
//            "left JOIN permission_functionpage pf on pf.permission_id = p.id " +
//            "LEFT JOIN function_page fp on fp.id = pf.function_page_id " +
//            "where doctor_jobnum = #{jobnum} and fp.id is not NULL")
//    public List<FunctionPage> getUserMenu(String jobnum);

//    @Select("SELECT DISTINCT fp.id,fp.pagename,fp.pagedescribe,fp.title,fp.titleflag,fp.url FROM role r\n" +
//            "LEFT JOIN role_permission rp on rp.role_id = rp.role_id\n" +
//            "LEFT JOIN permission p on p.id = rp.permission_id\n" +
//            "left JOIN permission_functionpage pf on pf.permission_id = p.id\n" +
//            "LEFT JOIN function_page fp on fp.id = pf.function_page_id\n" +
//            "WHERE r.id = #{roleid} and fp.id is not NULL")
//    public List<FunctionPage> getUserMenu(Integer roleid);
    @Select("SELECT DISTINCT fp.id,fp.pagename,fp.pagedescribe,fp.title,fp.titleflag,fp.url  FROM role r\n" +
            "LEFT JOIN role_permission rp on rp.role_id = rp.role_id\n" +
            "LEFT JOIN permission p on p.id = rp.permission_id\n" +
            "left JOIN permission_functionpage pf on pf.permission_id = p.id\n" +
            "LEFT JOIN function_page fp on fp.id = pf.function_page_id\n" +
            "WHERE role_id = #{roleid} and fp.id is not NULL")
    public List<FunctionPage> getUserMenu(Integer roleid);


}
